<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>邮件发送系统</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="page-header">
                    <h1>邮件发送 <small>使用网易邮箱发送</small></h1>
                </div>
                <div class="form-group">
                    <label for="to">邮件地址</label>
                    <input type="email" class="form-control" id="to" value="15800047822@139.com" placeholder="toMail">
                </div>
                <div class="form-group">
                    <label for="title">邮件主题</label>
                    <input type="text" class="form-control" id="title" placeholder="title">
                </div>
                <div class="form-group">
                    <label for="content">主题内容</label>
                    <textarea id="content" class="form-control" rows="10" placeholder="content"></textarea>
                </div>
                <button id="sent" type="button" class="btn btn-primary btn-block">发送邮件</button>
            </div>
        </div>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.5.0/axios.min.js"></script>
<script>
    $(() => {
        $("#sent").on('click', () => {
            var param = {
                to: $("#to").val(),
                title: $("#title").val(),
                content: $("#content").val(),
            };

            axios.post('/test/email', param).then(res => {
                console.log(res)

                if (res.status === 200) {
                    alert(!res.data.error ? "邮件发送成功" : res.data.message);
                }
            }, res => {
                console.error(res);
                alert(res.message);
            })

            /*
            $.ajax({
                url: '/test/email',
                type: 'POST',
                data: JSON.stringify(param),
                dataType: 'JSON',
                contentType: "application/json",
                success (data) {           //成功回调
                    if (data.error) {
                        alert("发送失败，原因：" + data.message);
                        return;
                    }

                    alert("发送成功");
                }
            });//*/
        })
    })
</script>
</html>